package org.example.myleet.p748;

public class Solution {
    public String shortestCompletingWord(String licensePlate, String[] words) {
        int[] licenseCount = new int[26];
        for (char c : licensePlate.toCharArray()) {
            if (Character.isAlphabetic(c)) {
                ++licenseCount[Character.toLowerCase(c) - 'a'];
            }
        }
        String candidate = "aaaaaaaaaaaaaaaa";
        for (String word : words) {
            int[] wordCount = new int[26];
            for (char c : word.toCharArray()) {
                ++wordCount[c - 'a'];
            }
            boolean complete = true;
            for (int i = 0; i < 26; ++i) {
                if (wordCount[i] < licenseCount[i]) {
                    complete = false;
                    break;
                }
            }
            if (complete) {
                if (candidate.length() > word.length()) {
                    candidate = word;
                }
            }
        }
        return candidate;
    }
}
